package m2;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.MessageProperties;

import java.util.Scanner;

public class Producer {
    public static void main(String[] args) throws Exception {
        //连接服务器
        ConnectionFactory f=new ConnectionFactory();
        f.setHost("192.168.64.140");
        f.setUsername("admin");
        f.setPassword("admin");

        Connection con=f.newConnection();
        Channel c=con.createChannel();

        /*
            true -持久队列
         */
        c.queueDeclare("task-queue",true,false,false,null);
        while (true){
            System.out.print("输入消息: ");
            String s = new Scanner(System.in).nextLine();

            //第三个参数设置消息持久化
            c.basicPublish("", "task-queue", MessageProperties.PERSISTENT_TEXT_PLAIN, s.getBytes());
        }
    }
}
